import yagmail
from utils.read_config import ReadConfig


class SendEmail:
    """
    通过 邮箱发送测试报告 的类
    """

    # 读取config.yml配置文件中email_qq的相关配置
    email_qq_data = ReadConfig.read_config_by_key("config.yml", "email")["qq"]

    @classmethod
    def send_mail_by_qq(cls, report_path, subject="测试报告", contents="你好，测试报告请查收"):
        """
        通过qq邮箱发送测试报告
        :param report_path: 附件 测试报告html文件位置
        :param subject: 邮件主题
        :param contents: 邮件内容
        """
        # 基本配置
        mail = yagmail.SMTP(user=cls.email_qq_data["user"], password=cls.email_qq_data["password"],
                            host=cls.email_qq_data["host"],)
        # 发送
        mail.send(cls.email_qq_data["to"], subject, contents, report_path)
